package com.jcl.recruit.common.service;

import com.jcl.recruit.apply.model.InterviewSkd;
import com.jcl.recruit.resume.model.Resume;
import com.jcl.weaver.webservice.HrmService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;

/**
 * @author 刘明新
 * @date 2018/8/3 下午2:52
 */
@Service
public class CommonService {

    private static final Logger log = LoggerFactory.getLogger(CommonService.class);

    public static List<String> splitString(String str,String split){
        if(StringUtils.isBlank(str) || StringUtils.isBlank(split)){
            return null;
        }
        String[] strs=str.split(split);
        List<String> list= Arrays.asList(strs);
        return list;
    }

    /**
     * 下划线命名转为驼峰命名
     * @param para
     * @return
     */
    public static String UnderlineToHump(String para){
        StringBuilder result=new StringBuilder();
        String a[]=para.split("_");
        for(String s:a){
            if(result.length()==0){
                result.append(s.toLowerCase());
            }else{
                result.append(s.substring(0, 1).toUpperCase());
                result.append(s.substring(1).toLowerCase());
            }
        }
        return result.toString();
    }

    public class synResume implements Runnable{
        private List <InterviewSkd> skds;
        private String createrId;
        private Resume resume;
        public synResume(List<InterviewSkd> skds,String createrId,Resume resume){
            this.skds = skds;
            this.createrId = createrId;
            this.resume = resume;
        }

        @Override
        public void run() {
            String skd = "";
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            for (InterviewSkd entity : skds) {
                skd = skd + "<testDate1>" + sdf.format(entity.getScheduleDate()) + "</testDate1>" +
                        "<testTime1>" + entity.getScheduleTime() + "</testTime1>" +
                        "<userId1>" + entity.getManagerId() + "</userId1>" +
                        "<opinion1>" + entity.getResult() + "</opinion1>" +
                        "<attend1>" + entity.getStatus() + "</attend1>";
            }
            HrmService hrmService = new HrmService();
            String xmlstr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                    "<root>" +
                    "<tplist>" +
                    "<tp action=\"add\">" +
                    "    <creater>" + createrId + "</creater>" +
                    "<name>" + resume.getRealname() + "</name>" +
                    "<phone>" + resume.getMobile() + "</phone>" +
                    "<mail>" + resume.getEmail() + "</mail>" +
                    "<residence>" + resume.getCurrentCity() + "</residence>" +
                    "<channel>投递</channel>" +
                    "<noticeDate>" + sdf.format(resume.getApplyDate()) + "</noticeDate>" +
                    "<intention>" + resume.getTags() + "</intention>" +
                    "<applyPost>" + resume.getApplyPosition() + "</applyPost>" +
                    "<result></result>" +
                    skd +
                    "<remark></remark>" +
                    "<fileIds></fileIds>" +
                    "" +
                    "" +
                    "<deleted>0</deleted>" +
                    "<workPlanId1></workPlanId1>" +
                    "<workPlanId2></workPlanId2>" +
                    "<workPlanId3></workPlanId3>" +
                    "<workPlanId4></workPlanId4>" +
                    "" +
                    "<contactDate></contactDate>" +
                    "<webnumber></webnumber>" +
                    "<channelinfo>" + resume.getSourceSub() + "</channelinfo>" +
                    "<entrydate></entrydate>" +
                    "<entrydate2></entrydate2>" +
                    "<education>" + resume.getEduLastEducation() + "</education>" +
                    "<school>" + resume.getEduLastSchool() + "</school>" +
                    "<major>" + resume.getEduLastMajor() + "</major>" +
                    "<other1></other1>" +
                    "<other2></other2>" +
                    "<other3></other3>" +
                    "<other4></other4>" +
                    "<otherPhone></otherPhone>" +
                    "<taidu>1</taidu>" +
                    "<nengli>1</nengli>" +
                    "<qianli>1</qianli>" +
                    "</tp>" +
                    "</tplist>" +
                    "</root>";
            System.out.println(xmlstr);
            String bean = hrmService.getHrmServiceHttpPort().synTalentedPerson("", xmlstr);
            System.out.println(bean);
            System.out.println("异步请求结束");
        }
    }
}
